using Godot;
using System;
using System.ComponentModel.DataAnnotations;
using System.Numerics;

public partial class Camera2d : Camera2D
{
    [Export]
    public float zoom_incerment = 0.1f;//缩放增量
    [Export]
    public float zoom_max = 1f;
    [Export]
    public float zoom_min = 0.2f;
    [Export]
    public float zoom_rate = 10f;
    public float zoom_target = 1f;
    public bool is_zoom = false;

    public void ZoomIn()
    {
        zoom_target = Math.Max(zoom_min , zoom_target - zoom_incerment);
        is_zoom = true;
    }

    public void ZoomOut()
    {
        zoom_target = Math.Min(zoom_max , zoom_target + zoom_incerment);
        is_zoom = true;
    }

    public override void _Input(InputEvent @event)
    {
        if (@event is InputEventMouseButton)
        {
            InputEventMouseButton input_event = @event as InputEventMouseButton;
            GD.Print("gunlun");
            if(input_event.ButtonIndex == MouseButton.WheelDown)
            {
                ZoomIn();
            }
            else if (input_event.ButtonIndex == MouseButton.WheelUp)
            {
                ZoomOut();
            }
        }
    }

    public override void _PhysicsProcess(double delta)
    {
        base._PhysicsProcess(delta);
        if(is_zoom)
        {
            Zoom = Zoom.Lerp(zoom_target * Godot.Vector2.One , (float)delta * zoom_rate);
            if(zoom_target == Zoom.X)
            {
                is_zoom = false;
            }
        }
    }
}
